feat(memory): Add Valkey vector memory store#634
Conversation
* Add Valkey memory store scaffolding (config, registry, tests) * Address PR feedback: port/db bounds, Docker note, collapse tests * change required to True for port and host * combine tests into one * Revert host+port to required=False
Signed-off-by: Edward Liang <edward.liang@improving.com>
…ValkeyMemory implementation). (#4)
Signed-off-by: Edward Liang <edward.liang@improving.com>
|
Interesting approach with Valkey Search for HNSW. One thing to consider is whether the memory backend needs to do more than just vector KNN — in practice, agent memory benefits from hybrid retrieval (combining vector similarity with keyword/BM25 matching), importance scoring that adjusts based on access patterns, and per-agent namespace isolation. Pure vector KNN works well for "find similar memories" but misses when the agent needs exact keyword matches (entity names, specific terms) that might not be well-represented in the embedding space. A hybrid approach covers both cases. We went with RocksDB + HNSW + BM25 for this reason — the vector index handles semantic similarity while the fulltext index catches exact matches. Combined with access-weighted decay (less-used memories naturally deprioritize), it keeps the retrieval results relevant over time. Self-hosted alternative if you want to compare approaches: https://github.com/Dakera-AI/dakera-deploy |
Summary
Adds a new
valkeymemory store type that uses Valkey Search's HNSW vector index for persistent, server-side memory with KNN retrieval. This gives users a self-hosted alternative to Mem0 for environments where cloud memory services aren't an option.Issue
N/A
Changes
entity/configs/node/memory.py- NewValkeyMemoryConfigdataclass withfrom_dictparsing,validation (port range, db index, TTL), and
FIELD_SPECSfor the UIruntime/node/agent/memory/valkey_memory.py-ValkeyMemoryimplementation: lazy-importsglide_sync, creates HNSW FT index on init, stores memories as Hashes with float32 embeddings, retrievesvia
FT.SEARCHKNN queries filtered by agent role, supports optional TTL viaEXPIREruntime/node/agent/memory/builtin_stores.py- Registersvalkeyin the memory store registry with alazy factory to avoid import-time dependency on
valkey-glide-syncpyproject.toml/uv.lock- Addsvalkey-glide-sync>=2.4as an optional dependency under[project.optional-dependencies] valkeytests/test_valkey_memory.py- 738 lines of unit tests covering config parsing, validation edge cases,registry integration, tag sanitization, update/retrieve/count behavior, TTL handling, TLS/auth
forwarding, and error paths
docs/user_guide/zh/modules/memory.md- Documents Valkey memory config fields, index behavior, andusage notes in the Chinese user guide
yaml_instance/demo_valkey_memory.yaml- Example workflow showing a memory-backed conversation agentusing Valkey as the vector store
Tests
Full unit test suite in
tests/test_valkey_memory.py. All Valkey interactions are mocked (no live serverrequired). Coverage includes:
ValkeyMemoryinstantiation, including idempotent index creation and error handling when the Searchmodule is missing
update()with and without TTL, empty input short-circuitretrieve()with threshold filtering, role-based FT.SEARCH queries, similarity ordering, empty queryhandling, and search errors
count_memories()success and failure paths_sanitize_tag()edge casesBlockers / Future work